/**
 * Created by hsia on 2017/7/17.
 */

// 今天
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
//alert(today);
var oneday = 1000 * 60 * 60 * 24;
// 昨天
today = today+oneday;
var yesterday = new Date(today - oneday);
//alert(yesterday);
// 上周一
var lastMonday = new Date(today- oneday * (today.getDay() + 6));
alert(lastMonday);
// 上个月1号
var lastMonthFirst = new Date(today - oneday * today.getDate());
lastMonthFirst = new Date(lastMonthFirst - oneday * (lastMonthFirst.getDate() - 1));
alert(lastMonthFirst);

var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
today.setMilliseconds(0);
var today = new Date("2012/11/05 24:00").getTime();
alert(today);

var now= new Date();
var year=now.getYear();
var month=now.getMonth()+1;
var day=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now.getSeconds();
alert(year+"-"+month+"-"+day+" "+hour+":"+":"+minute+":"+second);
var jsunix = Math.round(new Date().getTime()/1000);//获取当前时间时间戳
//alert(jsunix); //1425307045 getTime()返回数值的单位是毫秒 当前时间的时间戳 2015/3/2 22:37:25
//var test = Math.round(new Date("2012/11/05 24:00").getTime()/1000);
var test = Math.round(new Date("11/05/2012").getTime()/1000); //1352044800
alert(test);
function MillisecondToDate(msd) {
    var time = parseFloat(msd) /1000;
    if (null!= time &&""!= time) {
        if (time >60&& time <60*60) {
            time = parseInt(time /60.0) +"分钟"+ parseInt((parseFloat(time /60.0) -
                    parseInt(time /60.0)) *60) +"秒";
        }else if (time >=60*60&& time <60*60*24) {
            time = parseInt(time /3600.0) +"小时"+ parseInt((parseFloat(time /3600.0) -
                    parseInt(time /3600.0)) *60) +"分钟"+
                parseInt((parseFloat((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60) -
                    parseInt((parseFloat(time /3600.0) - parseInt(time /3600.0)) *60)) *60) +"秒";
        }else {
            time = parseInt(time) +"秒";
        }
    }else{
        time = "0 时 0 分0 秒";
    }
    return time;
}

//var nowunix = Math.round(new Date().getTime()/1000);//获取当前时间时间戳
var nowunix = Math.round(new Date().getTime());//获取当前时间时间戳
//alert(nowunix); //1425309475 2015/3/2 23:17:55
var date = new Date();
date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
//hao = date.getTime();//本来有
//alert(hao); //1425308400031
//获取指定时间时间戳
//var secunix = Math.round(date.getTime()/1000);
var secunix = Math.round(date.getTime());
//alert(secunix); //23点59分59秒 1425312000 2015/3/3 0:0:0
shengunix = secunix-nowunix;
//alert(shengunix); //2740 2305
alert(MillisecondToDate(shengunix));